package de.mhu.mandalaui.text;

import de.mhu.mandalaui.Component;
import de.mhu.mandalaui.Response;

public class Text extends Component {

	public enum TYPE {SIMPLE,BOLD,SMALL,ITALIC, H1, H2, H3, H4};
	private TYPE type = TYPE.SIMPLE;
	private String text = null;
	
	public Text() {
	}
	
	public Text(String text) {
		this.text = text;
	}
	
	public Text(TYPE type, String text) {
		this.type = type;
		this.text = text;
	}
	
	@Override
	protected void doInitialize() {
	}

	@Override
	protected void doDestroy() {
	}

	@Override
	public void render(Response response) {
		if (text == null) return;
		switch (type) {
		case BOLD:
			response.startTag("strong", null, this);
			break;
		case ITALIC:
			response.startTag("em", null, this);
			break;
		case SIMPLE:
			response.startTag("span", null, this);
			break;
		case SMALL:
			response.startTag("small", null, this);
			break;
		default:
			response.startTag(type.name().toLowerCase(), null, this);
		}
		
		response.appendText(text);
		
		switch (type) {
		case BOLD:
			response.endTag("strong");
			break;
		case ITALIC:
			response.endTag("em");
			break;
		case SIMPLE:
			response.endTag("span");
			break;
		case SMALL:
			response.endTag("small");
			break;
		default:
			response.endTag(type.name().toLowerCase());
		}
		
	}

	public void setText(String text) {
		this.text = text;
	}

	public String getText() {
		return text;
	}

	public String getStyleBase() {
		return "text";
	}

}
